using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Extended.NetRouting.Test
{
    [TestClass]
    public class ToolsTest
    {
        [TestMethod]
        public void SelectByMinTest()
        {
            var data = GetTestData();
            var actual = data.SelectByMin(p => p.Item2);
            var expected = data[4];

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void SelectByMaxTest()
        {
            var data = GetTestData();
            var actual = data.SelectByMax(p => p.Item2);
            var expected = data[6];

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void SelectByMinOnEmptyList()
        {
            var data = new Tuple<string, int>[] { };
            var actual = data.SelectByMax(p => p.Item2);
            Tuple<string, int> expected = null;

            Assert.AreEqual(expected, actual);
        }

        private static Tuple<string, int>[] GetTestData()
        {
            return new[]
                       {
                           new Tuple<string, int>("item 1", 2),
                           new Tuple<string, int>("item 2", 1),
                           new Tuple<string, int>("item 3", 4),
                           new Tuple<string, int>("item 4", 7),
                           new Tuple<string, int>("item 5", 0),
                           new Tuple<string, int>("item 6", 6),
                           new Tuple<string, int>("item 7", 8),
                           new Tuple<string, int>("item 8", 5),
                       };
        }
    }
}